package io.github.yidasanqian.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class HelloService {

    @Resource
    private RestTemplate restTemplate;

    public String hiService(String name) {
        return restTemplate.getForObject("http://hello-service/hi?name=" + name, String.class);
    }

    @HystrixCommand(fallbackMethod = "helloConsumerFallback")
    public String helloConsumer() {
        return restTemplate.getForEntity("http://hello-service/hello", String.class).getBody();
    }

    // 服务降级
    public String helloConsumerFallback() {
        return "helloConsumerFallback error";
    }
}
